package pv.util;

import pv.finder.R;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ProgressBar;

public class CustomSimpleProgressDialog extends Dialog {

    protected static CustomSimpleProgressDialog dialog;

    public static synchronized CustomSimpleProgressDialog show(Context context,
                                                               final AsyncTask asyncTask) {
        try {

            if (dialog == null) {
                dialog = new CustomSimpleProgressDialog(context);
            }
            if (dialog.isShowing()) {
                dialog.dismiss();
            }


            dialog.setCancelable(true);
            if (asyncTask != null) {
                dialog.setOnCancelListener(new OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface dialog) {
                        // TODO Auto-generated method stub
                        asyncTask.cancel(true);
                    }
                });
            }
            dialog.show();
        } catch (Exception e) {

        }
        return dialog;
    }

    protected CustomSimpleProgressDialog(Context context) {
        super(context, R.style.CustomSimpleProcessDialog);
        setContentView(getView(context), new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        setTitle(null);
    }

    protected static View getView(Context context) {
        return new ProgressBar(context);
    }

    // public CustomSimpleProgressDialog(Context context, AsyncTask asyncTask) {
    // super(context, R.style.CustomSimpleProcessDialog);
    // this.asyncTask = asyncTask;
    //
    // }
}
